import sys
from typing import Annotated

sys.path.append(r'D:\华清\large-model-deployment\ChatGLM3量化模型（平替）\示例代码\工具调用')

from register_tool import register_tool
# 使用搜索引擎的工具
from tavily import TavilyClient
# 格式化输出
from pprint import pformat


@register_tool
def search(query: Annotated[str, '查询关键字', True]):
    """搜索引擎"""
    # 1. 创建客户端工具
    client = TavilyClient(api_key='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')

    # 2. 搜索
    response = client.search(query, max_results=3)

    print(pformat(response))
    # return str(response)


# if __name__ == '__main__':
    # 这个需要翻墙
    # from duckduckgo_search import DDGS
    #
    # results = DDGS().text("黑神话悟空", max_results=3)
